package com.vf.admin.client.controller;

import com.vf.admin.client.common.ClientBaseController;
import com.vf.admin.client.common.ClientConstants;
import com.vf.admin.client.common.RedisKeys;
import com.vf.admin.client.dto.CaiFuJiLuDto;
import com.vf.admin.client.dto.ZhangDanLiWuDto;
import com.vf.admin.client.service.*;
import com.vf.admin.common.entity.Result;
import com.vf.admin.common.redis.RedisUtil;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import static com.vf.admin.utils.StringEx.isNull;

/**
 * @author anxiang
 * @version 1.0.0
 * @ClassName AppZhangHuController.java
 * @Description 账户明细
 * @createTime 2021年07月23日 15:29:00
 */

@Controller
@RequestMapping("/app/mingxi")
public class AppZhangHuController extends ClientBaseController {

    @Autowired
    AppMingxiChongzhiService appMingxiChongzhiService;
    @Autowired
    AppMingxiJinbiService appMingxiJinbiService;
    @Autowired
    AppMingxiFreetimeService appMingxiFreetimeService;
    @Autowired
    AppMingxiMeilizhiService appMingxiMeilizhiService;
    @Autowired
    AppMingXiZuanShiService appMingXiZuanShiService;
    @Autowired
    AppMingXiTxService appMingXiTxService;
    @Autowired
    AppMingxiDuihuanService appMingxiDuihuanService;
    @Autowired
    AppMingXiShouLiService appMingXiShouLiService;
    @Autowired
    AppMingXiSongLiService appMingXiSongLiService;
    @Autowired
    AppUserService appUserService;
    @Autowired
    AppCashWithdrawalService cashWithdrawalService;
    @Autowired
    ExchangeGoldDiamondsLogService exchangeGoldDiamondsLogService;
    @Autowired
    RedisUtil redisUtil;

    /**
     * @Description 账单：金币
     * @Param: pageno
     * @return: com.vf.admin.common.entity.Result
     * @Author: ljx
     * @Date: 2021/07/23
     */
    @ResponseBody
    @RequestMapping("/jinbilist")
    public Result jinbilist(Integer pageno) {
        try {
            if (isNull(pageno)) return this.errorJSON("页码不能为空");
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            //获取当前登录用户的user对象
            AppUser user = appUserService.get(userId);
            //分页数量
            SplitPageBean splitPageBean = new SplitPageBean(pageno, 20);
            List<CaiFuJiLuDto> caiFuJiLuDtoList = new ArrayList<>();
            //查询金币明细
            List<AppMingxiJinbi> czList = appMingxiJinbiService.findList(user.getId(), splitPageBean);
            for (AppMingxiJinbi appMingxiJinbi : czList) {
                CaiFuJiLuDto cf = new CaiFuJiLuDto();
                cf.setNeirong(appMingxiJinbi.getBeizhu());
                cf.setQianshu(appMingxiJinbi.getNum());
                cf.setTime(appMingxiJinbi.getCreatetime());
                cf.setLeixing(appMingxiJinbi.getLeixing());
                caiFuJiLuDtoList.add(cf);
            }
            return this.sucessPage(caiFuJiLuDtoList, splitPageBean.getNextPageNo());
        } catch (Exception e) {
            e.printStackTrace();
            return this.errorJSON("网络繁忙，请稍后重试");
        }
    }


    /**
     * @Description 账单：魅力
     * @Param: pageno
     * @return: com.vf.admin.common.entity.Result
     * @Author: ljx
     * @Date: 2021/07/23
     */
    @ResponseBody
    @RequestMapping("/meililist")
    public Result meililist(Integer pageno) {
        try {
            if (isNull(pageno)) return this.errorJSON("页码不能为空");
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            //获取当前登录用户的user对象
            AppUser user = appUserService.get(userId);

            //分页数量
            SplitPageBean splitPageBean = new SplitPageBean(pageno, 20);
            List<CaiFuJiLuDto> caiFuJiLuDtoList = new ArrayList<>();
            //查询金币明细
            List<AppMingxiMeilizhi> czList = appMingxiMeilizhiService.findList(user.getId(), splitPageBean);
            for (AppMingxiMeilizhi appMingxiMeilizhi : czList) {
                CaiFuJiLuDto cf = new CaiFuJiLuDto();
                cf.setNeirong(appMingxiMeilizhi.getBeizhu());
                cf.setQianshu(new BigDecimal(appMingxiMeilizhi.getNum()));
                cf.setTime(appMingxiMeilizhi.getCreatetime());
                cf.setLeixing(appMingxiMeilizhi.getLeixing());
                caiFuJiLuDtoList.add(cf);
            }
            return this.sucessPage(caiFuJiLuDtoList, splitPageBean.getNextPageNo());
        } catch (Exception e) {
            e.printStackTrace();
            return this.errorJSON("网络繁忙，请稍后重试");
        }
    }

    /**
     * @Description 账单：钻石
     * @Param: pageno
     * @return: com.vf.admin.common.entity.Result
     * @Author: ljx
     * @Date: 2021/07/23
     */
    @ResponseBody
    @RequestMapping("/zuanshilist")
    public Result zuanshilist(Integer pageno) {
        try {
            if (isNull(pageno)) {
                return this.errorJSON("页码不能为空");
            }
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            //获取当前登录用户的user对象
            AppUser user = appUserService.get(userId);

            //分页数量
            SplitPageBean splitPageBean = new SplitPageBean(pageno, 20);
            List<CaiFuJiLuDto> caiFuJiLuDtoList = new ArrayList<>();
            //查询钻石明细
            List<AppMingXiZuanShi> czList = appMingXiZuanShiService.findList(user.getId(), splitPageBean);
            for (AppMingXiZuanShi appMingXiZuanShi : czList) {
                CaiFuJiLuDto cf = new CaiFuJiLuDto();
                cf.setNeirong(appMingXiZuanShi.getBeizhu());
                cf.setQianshu(appMingXiZuanShi.getNum());
                cf.setTime(appMingXiZuanShi.getCreatetime());
                cf.setLeixing(appMingXiZuanShi.getLeixing());
                caiFuJiLuDtoList.add(cf);
            }
            return this.sucessPage(caiFuJiLuDtoList, splitPageBean.getNextPageNo());
        } catch (Exception e) {
            e.printStackTrace();
            return this.errorJSON("网络繁忙，请稍后重试");
        }
    }
    /**
     * @Description 账单：充值、兑换、 提现
     * @Param: leixing 账单类型  1充值   2提现
     * @Param: pageno
     * @return: com.vf.admin.common.entity.Result
     * @Author: ljx
     * @Date: 2021/07/23
     */
    @ResponseBody
    @RequestMapping("/caifulist")
    public Result caifulist(Integer leixing, Integer pageno) {
        try {
            if (isNull(leixing)) {
                return this.errorJSON("类型错误");
            }
            if (isNull(pageno)) {
                return this.errorJSON("页码不能为空");
            }

            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            //获取当前登录用户的user对象
            AppUser user = appUserService.get(userId);

            //分页数量
            SplitPageBean splitPageBean = new SplitPageBean(pageno, 20);
            List<CaiFuJiLuDto> caiFuJiLuDtoList = new ArrayList<>();
            //根据类型查询数据
            switch (leixing) {
                case 1:
                    List<AppMingxiChongzhi> czList = appMingxiChongzhiService.findList(user.getId(), splitPageBean);
                    for (AppMingxiChongzhi appMingxiChongzhi : czList) {
                        CaiFuJiLuDto cf = new CaiFuJiLuDto();
                        cf.setNeirong("钻石充值");
                        cf.setQianshu(appMingxiChongzhi.getGoumainum());
                        cf.setTime(appMingxiChongzhi.getCreatetime());
                        cf.setLeixing(1);
                        caiFuJiLuDtoList.add(cf);
                    }
                    break;
                case 2:
                    List<AppCashWithdrawal> txList = cashWithdrawalService.findList(user.getId(), splitPageBean);
                    for (AppCashWithdrawal appMingXiTx : txList) {
                        CaiFuJiLuDto cf = new CaiFuJiLuDto();
                        cf.setNeirong("金币提现");
                        cf.setQianshu(appMingXiTx.getMoney());
                        cf.setTime(appMingXiTx.getCreatetime());
                        cf.setLeixing(2);
                        cf.setStatus(appMingXiTx.getStatus());
                        caiFuJiLuDtoList.add(cf);
                    }
                    break;
                default:
            }
            return this.sucessPage(caiFuJiLuDtoList, splitPageBean.getNextPageNo());
        } catch (Exception e) {
            e.printStackTrace();
            return this.errorJSON("网络繁忙，请稍后重试");
        }


    }

    /**
     * 账单：收礼、送礼
     *
     * @Description 账户详情 账单：收礼、送礼
     * @Param: leixing 1收礼  2送礼
     * @Param: pageno 页码
     * @return: com.vf.admin.common.entity.Result
     * @Author: ljx
     * @Date: 2021/07/23
     */
    @ResponseBody
    @RequestMapping("/liwulist")
    public Result liwulist(Integer leixing, Integer pageno) {
        System.out.println("leixing:"+leixing);
        try {
            if (isNull(leixing)) {
                return this.errorJSON("类型错误");
            }
            if (isNull(pageno)) {
                return this.errorJSON("页码不能为空");
            }
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            //获取当前登录用户的user对象
            AppUser user = appUserService.get(userId);
            //分页数量
            SplitPageBean splitPageBean = new SplitPageBean(pageno, 10);
            List<ZhangDanLiWuDto> zhangDanLiWuDtos = new ArrayList<>();
            //根据类型查询数据
            switch (leixing) {
                case 1:
                    List<AppMingXiShouLi> slList = appMingXiShouLiService.findList(user.getId(), splitPageBean);
                    for (AppMingXiShouLi appMingXiShouLi : slList) {
                        ZhangDanLiWuDto zhangDanLiWuDto = new ZhangDanLiWuDto();
                        zhangDanLiWuDto.setTouxiang(appMingXiShouLi.getSluserpic());
                        zhangDanLiWuDto.setMingzi(appMingXiShouLi.getSlusernick());
                        zhangDanLiWuDto.setLiwu(appMingXiShouLi.getGiftname());
                        zhangDanLiWuDto.setLiwutupian(appMingXiShouLi.getGiftpic());
                        zhangDanLiWuDto.setLiwushuliang(appMingXiShouLi.getLiwunum());
                        zhangDanLiWuDto.setMeilishuliang(appMingXiShouLi.getFujianum().longValue());
                        zhangDanLiWuDto.setShijian(appMingXiShouLi.getCreatetime());
                        zhangDanLiWuDtos.add(zhangDanLiWuDto);
                    }
                    break;
                case 2:
                    List<AppMingXiSongLi> slList2 = appMingXiSongLiService.findList(user.getId(),splitPageBean);
                    for (AppMingXiSongLi appMingXiShouLi : slList2){
                        ZhangDanLiWuDto zhangDanLiWuDto = new ZhangDanLiWuDto();
                        zhangDanLiWuDto.setTouxiang(appMingXiShouLi.getSluserpic());
                        zhangDanLiWuDto.setMingzi(appMingXiShouLi.getSlusernick());
                        zhangDanLiWuDto.setLiwu(appMingXiShouLi.getGiftname());
                        zhangDanLiWuDto.setLiwutupian(appMingXiShouLi.getGiftpic());
                        zhangDanLiWuDto.setLiwushuliang(appMingXiShouLi.getLiwunum());
                        zhangDanLiWuDto.setMeilishuliang(appMingXiShouLi.getFujianum());
                        zhangDanLiWuDto.setShijian(appMingXiShouLi.getCreatetime());
                        zhangDanLiWuDtos.add(zhangDanLiWuDto);
                    }
                    break;
                default:
            }
            return this.sucessPage(zhangDanLiWuDtos, splitPageBean.getNextPageNo());
        } catch (Exception e) {
            e.printStackTrace();
            return this.errorJSON("网络繁忙，请稍后重试");
        }
    }

    /**
     * @Description 账单：免费时长
     * @Param: pageno
     * @return: com.vf.admin.common.entity.Result
     * @Author: ljx
     * @Date: 2021/07/23
     */
    /*@ResponseBody
    @RequestMapping("/freetimelist")
    public Result freetimelist(Integer pageno) {
        try {
            if (isNull(pageno)) {
                return this.errorJSON("页码不能为空");
            }
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            //获取当前登录用户的user对象
            AppUser user = appUserService.get(userId);

            //分页数量
            SplitPageBean splitPageBean = new SplitPageBean(pageno, 20);
            List<CaiFuJiLuDto> caiFuJiLuDtoList = new ArrayList<>();
            //查询金币明细
            List<AppMingxiFreetime> czList = appMingxiFreetimeService.findList(user.getId(), splitPageBean);
            for (AppMingxiFreetime appMingxiFreetime : czList) {
                CaiFuJiLuDto cf = new CaiFuJiLuDto();
                cf.setNeirong(appMingxiFreetime.getBeizhu());
                cf.setQianshu(appMingxiFreetime.getNum());
                cf.setTime(appMingxiFreetime.getCreatetime());
                cf.setLeixing(appMingxiFreetime.getLeixing());
                caiFuJiLuDtoList.add(cf);
            }
            return this.sucessPage(caiFuJiLuDtoList, splitPageBean.getNextPageNo());
        } catch (Exception e) {
            e.printStackTrace();
            logger.debug("免费时长明细记录接口异常" + e);
            return this.errorJSON("网络繁忙，请稍后重试");
        }
    }
*/

}
